<template>
	<view>
		<view class="box">
			<image :src="loginbanner" class="sign-banner" alt=""></image>
			<image :src="loginlogo" class="sign-logo" alt=""></image>
			<view class="sign-box">
				<h3>注册账号</h3>
				<view class="same-btn account">
					<label class="iconfont iconfonts icon-ym-people"></label>
					<input type="text" v-model="Verification.mobile" name="mobile" placeholder="请输入手机号">
				</view>
				<view class="same-btn password">
					<label class="iconfont iconfonts icon-ym-thecode"></label>
					<input type="text" v-model="Verification.smscode" id="smsCode" @blur="inputblur" placeholder="请输入验证码">
					<view class="getcode" @click="getcode" :class="clickable?'color-4869EE':'color-9A9A9A'">{{getCode}}</view>
				</view>
				<view class="set">
					<view @click="tosign">返回登录</view>
				</view>
				<view class="sign-btn" @click="loginnext">
					下一步
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import helper from '@/common/js/helper.js'
	import config from '@/common/js/config.js'
	import graceChecker from '@/common/js/graceChecker.js'
	let rule = [{
		name: "mobile",
		checkType: "phoneno",
		checkRule: "",
		errorMsg: "手机号码有误"
	}, ];
	export default {
		data() {
			return {
				height1: "",
				lookpwd: true,
				getCode: "获取验证码",
				clickable: true,
				time: 60,
				Verification: {
					smscode: '',
					mobile: ''
				},
				loginbanner: config.Resources.banner.loginbanner,
				loginlogo: config.Resources.banner.loginlogo
			}
		},
		onLoad() {
			
			const app = getApp()
			// console.log(app)
		},
		methods: {
			tosign: function() {
				uni.redirectTo({
					url: '/pages/users/sign-in/sign-in'
				});
			},
			showHide: function() {
				this.lookpwd = !this.lookpwd;
			},
			getcode: function() {
				if (!this.clickable) {
					return;
				}
				if (this.Verification.mobile == '') {
					helper.msg('请输入手机号码!');
					return;
				}
				if (!graceChecker.check(this.Verification, rule)) {
					helper.msg(graceChecker.error);
					return;
				}
				this.clickable = false;
				// let apiKey= uni.getStorageSync('apiKey') ||'NET';
				// let baseUrlObj=config.Global.baseUrl;
				// let baseUrl=config.Global.baseUrl[apiKey].apiUrl;
				uni.request({
					url: config.Global.baseUrl.NET.apiUrl + '/api/Saas/Tenant/IsExistMobile/' + this.Verification.mobile,
					method: 'GET',
					success: success => {
						if (!success.data.data) {
							uni.request({
								url: config.Global.baseUrl.NET.apiUrl + '/api/Saas/Tenant/SmsVerifyCode/' + this.Verification.mobile +
									'/SMS_177245306',
								method: 'GET',
								success: res => {
									helper.msg(res.data.message);
								},
							})
							let clock = setInterval(() => {
								this.time--
								this.getCode = this.time + '秒后重新发送'
								if (this.time < 0) {
									clearInterval(clock);
									this.getCode = "获取验证码";
									this.clickable = true;
									this.time = 60;
								}
							}, 1000)
						} else {
							helper.msg('该账户已存在！');
							this.clickable = true;
						}
					},
				})
			},
			loginnext: function() {
				if (this.Verification.mobile != '' && this.Verification.smscode != '') {
					uni.navigateTo({
						url: '/pages/users/account/register-info/register-info?mobile=' + this.Verification.mobile + '&smscode=' +
							this.Verification.smscode
					});
				} else {
					helper.msg('手机验证不能为空！');
				}
			},
			inputblur(e) {
				this.Verification.smscode = e.detail.value;
			}
		}
	}
</script>

<style>
	.set {
		justify-content: flex-end;
	}
</style>
